package com.A21.GuoSai.demo.atom_adjust.jobworkers;

import com.A21.GuoSai.demo.service_entity.annotation.Author;
import com.A21.GuoSai.demo.service_entity.annotation.OutPutParam;
import com.A21.GuoSai.demo.service_entity.annotation.VariableType;
import com.A21.GuoSai.demo.workflow_adjust.service.FeelEngineService;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import io.camunda.zeebe.client.api.worker.JobClient;
import io.camunda.zeebe.spring.client.annotation.ZeebeVariable;
import io.camunda.zeebe.spring.client.annotation.ZeebeWorker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class Worker01 {

    @Autowired
    private FeelEngineService felEngineService;

    @ZeebeWorker(
            type = "a",
            name = "work01",
            forceFetchAllVariables = true
    )
    @Author(author = "FZ",attributeConnnect = "worker01")
    public void work01(final JobClient client, final ActivatedJob job,
                       @ZeebeVariable @VariableType(desc = "描述str1") String str1,
                       @ZeebeVariable @VariableType(desc = "描述str2") String str2,
                       @ZeebeVariable @VariableType(desc = "描述a1") Integer a1){
        Map<String,Object>map=job.getVariablesAsMap();
        log.info("worker01执行完毕");
        client.newCompleteCommand(job.getKey()).send().join();
    }


    @ZeebeWorker(
            type = "原子服务1",
            name = "原子服务1",
            forceFetchAllVariables = true
//            autoComplete = true
    )
    @Author(author = "FZ",attributeConnnect = "原子服务1")
    @OutPutParam(paramName = "c1",paramClass = String.class,desc = "原子服务1的输出")
    public void yuanzi01(final JobClient client, final ActivatedJob job,
                       @ZeebeVariable @VariableType(desc = "描述a1") Integer a1,
                       @ZeebeVariable @VariableType(desc = "描述b1") String b1){
        Map<String,Object>map=job.getVariablesAsMap();
        map.put("c1",String.valueOf(a1)+"---"+b1);
        log.info("原子服务1执行完毕");
        List<String> list = felEngineService.judgeWorker(job.getBpmnProcessId(), "原子服务1", map);
        list.forEach(System.out::println);
        client.newCompleteCommand(job.getKey()).variables(map).send().join();
    }


    @ZeebeWorker(
            type = "原子服务2",
            name = "原子服务2",
            forceFetchAllVariables = true
//            autoComplete = true
    )
    @Author(author = "FZ",attributeConnnect = "原子服务2")
    public void yuanzi02(final JobClient client, final ActivatedJob job,
                         @ZeebeVariable @VariableType(desc = "描述a2") Integer a2,
                         @ZeebeVariable @VariableType(desc = "描述b2") String b2,
                         @ZeebeVariable @VariableType(desc="描述c1")String c1){
        Map<String,Object>map=job.getVariablesAsMap();
        log.info("c1="+c1);
        log.info("原子服务2执行完毕");
        List<String> list = felEngineService.judgeWorker(job.getBpmnProcessId(), "原子服务2", map);
        list.forEach(System.out::println);
        client.newCompleteCommand(job.getKey()).send().join();
    }


    @ZeebeWorker(
            type = "原子服务3",
            name = "原子服务3",
            forceFetchAllVariables = true
//            autoComplete = true
    )
    @Author(author = "FZ",attributeConnnect = "原子服务3")
    public void yuanzi03(final JobClient client, final ActivatedJob job,
                         @ZeebeVariable @VariableType(desc = "描述a3",isStatic = false) Integer a3,
                         @ZeebeVariable @VariableType(desc = "描述b3") String b3){
        Map<String,Object>map=job.getVariablesAsMap();
        log.info("原子服务3执行完毕");
        List<String> list = felEngineService.judgeWorker(job.getBpmnProcessId(), "原子服务3", map);
        list.forEach(System.out::println);
        client.newCompleteCommand(job.getKey()).variables(map).send().join();
    }

    @ZeebeWorker(
            type = "原子服务4",
            name = "原子服务4",
            forceFetchAllVariables = true
//            autoComplete = true
    )
    @Author(author = "FZ",attributeConnnect = "原子服务4")
    public void yuanzi04(final JobClient client, final ActivatedJob job,
                         @ZeebeVariable @VariableType(desc = "描述a4",isStatic = false) Integer a4,
                         @ZeebeVariable @VariableType(desc = "描述b4") String b4){
        Map<String,Object>map=job.getVariablesAsMap();
        log.info("原子服务4执行完毕");
        List<String> list = felEngineService.judgeWorker(job.getBpmnProcessId(), "原子服务4", map);
        list.forEach(System.out::println);
        client.newCompleteCommand(job.getKey()).send().join();
    }
}
